package org.zfes.snowier.zbss.xzy.sms;

import java.util.Arrays;
import java.util.List;

import org.springframework.stereotype.Component;

import com.google.common.collect.Lists;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
//导入可选配置类
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
// 导入 SMS 模块的 client
import com.tencentcloudapi.sms.v20190711.SmsClient;
// 导入要请求接口对应的 request response 类
import com.tencentcloudapi.sms.v20190711.models.SendSmsRequest;
import com.tencentcloudapi.sms.v20190711.models.SendSmsResponse;
/**
* Tencent Cloud Sms Sendsms
* https://cloud.tencent.com/document/product/382/38778
*
*/
@Component
public class SmsTencentSender{
	
	
	private static String secretId="AKIDHD8pGQwOAm8E6jeE4gCSSDl24i8JNsHR";
	
	private static String secretKey="2pPxGDxkJdi3A0b1RfmhMn21kKerpYLs";
	public static void main(String[] args) {
		new SmsTencentSender().sendSms(Lists.newArrayList("+8615969701578"), "15215", "检测到隔壁老王摔倒");
	}
  public  void sendSms(List<String> phones,String deviceNum,String content) {
      try {
          Credential cred = new Credential(secretId,secretKey);
          HttpProfile httpProfile = new HttpProfile();
          httpProfile.setReqMethod("POST");
          httpProfile.setConnTimeout(60);
          httpProfile.setEndpoint("sms.tencentcloudapi.com");
          ClientProfile clientProfile = new ClientProfile();
          clientProfile.setSignMethod("HmacSHA256");
          clientProfile.setHttpProfile(httpProfile);
          SmsClient client = new SmsClient(cred, "",clientProfile);
          SendSmsRequest req = new SendSmsRequest();
          String appid = "1400474270";
          req.setSmsSdkAppid(appid);
          String sign = "汐众智能科技";
          req.setSign(sign);
          String senderid = "";
          req.setSenderId(senderid);
          String session = "";
          req.setSessionContext(session);
          String extendcode = "";
          req.setExtendCode(extendcode);
          String templateID = "846348";
          req.setTemplateID(templateID);
          String[] phoneNumbers = phones.toArray(new String[0]);//new String[] {phones};//{"+8613969137329", "+8615969701578"};//
          req.setPhoneNumberSet(phoneNumbers);
           /* 模板参数: 若无模板参数，则设置为空*/
          String[] templateParams = {deviceNum,content};//{"11111"};
          req.setTemplateParamSet(templateParams);
           /* 通过 client 对象调用 SendSms 方法发起请求。注意请求方法名与请求对象是对应的
           * 返回的 res 是一个 SendSmsResponse 类的实例，与请求对象对应 */
          SendSmsResponse res = client.SendSms(req);
           // 输出 JSON 格式的字符串回包
          System.out.println(SendSmsResponse.toJsonString(res));
           // 可以取出单个值，您可以通过官网接口文档或跳转到 response 对象的定义处查看返回字段的定义
          System.out.println(res.getRequestId());
       } catch (TencentCloudSDKException e) {
          e.printStackTrace();
      }
  }
}